<div class="overflow-x-auto mb-4">
  <table class="table">
    <!-- head -->
    <thead>
      <tr>
        <th>Credential Type</th>
        <th>Username</th>
        <th>Access Token</th>
        <th>Last Used</th>
        <th>Used By</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      <% current_user.providers.each do |provider| %>
        <% project_credential_providers = ProjectCredentialProvider.where(provider:).all %>
        <tr>
          <td>
          <%= provider.provider %>
          <br />
          <% if provider.container_registry? %>
            <span class="text-gray-500">
              <%= provider.registry_url %>
            </span>
          <% end %>
          </td>
          <td>
            <%= render "providers/show", provider: %>
          </td>
          <td>
            <% if provider.access_token %>
            <%= provider.access_token.first(4) %><%= "*" * [0, [10, provider.access_token.length - 6].min].max %><%= provider.access_token.last(2) %>
            <% else %>
              <span class="text-gray-500">
                N/A
              </span>
            <% end %>
          </td>
          <td>
            <%= (provider.last_used_at.strftime("%b %d, %Y") if provider.last_used_at) || "Never" %>
          </td>
          <td>
            <% project_credential_providers.each do |project_credential_provider| %>
              <%= link_to project_credential_provider.project.name, project_path(project_credential_provider.project), class: "hover: underline" %>
            <% end %>
          </td>
          <td>
            <% if project_credential_providers.empty? %>
              <%= link_to "Delete", provider, method: :delete, class: "btn btn-error btn-sm" %>
            <% else %>
              <%= link_to "Delete", "#", class: "btn btn-error btn-sm", disabled: true %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
